<script setup>
import { reactive } from "vue";
import { ElMessage } from "element-plus";
import { useRouter } from "vue-router";
// import { emitpostwords, LogoutApi } from "@/api";
// import { userPiniaStore } from "@/stores";
const router = useRouter();
// const userPinia = userPiniaStore();
const putPasswordForm = reactive({
  newPassword: "",
  confirmPassword: "",
  password: "",
  username: "",
});

const emitpasword = async () => {
  if (
    putPasswordForm.confirmPassword !== "" &&
    putPasswordForm.confirmPassword == putPasswordForm.newPassword
  ) {
    // const res = await emitpostwords(putPasswordForm);
    // if (res.data.code == 0) {
    //   ElMessage({
    //     message: "修改密码成功",
    //     type: "success",
    //   });

    //   localStorage.removeItem("token");
    //   localStorage.removeItem("user");
    //   router.replace("/");
    //   }
    ElMessage({
      message: "修改密码成功",
      type: "success",
    });
  } else {
    ElMessage({
      message: "修改密码失败,新密码和确认密码不一致",
      type: "error",
    });
  }
};

const logout = async () => {
  // const res = await LogoutApi();
  // if (res.data.code === 0) {
  localStorage.clear();
  sessionStorage.clear();
  // userPinia.user = {};
  ElMessage({
    message: "退出成功",
    type: "success",
  });
  router.replace("/");
  // }
};
</script>

<template>
  <div class="person-setting-page">
    <h3>修改密码</h3>
    <div class="content">
      <el-form :model="putPasswordForm" label-position="top">
        <el-form-item label="原密码：" :label-width="'60px'">
          <el-input
            v-model="putPasswordForm.password"
            type="password"
            show-password
            disabled
          />
        </el-form-item>
        <el-form-item label="新密码：" :label-width="'60px'">
          <el-input
            v-model="putPasswordForm.newPassword"
            type="password"
            show-password
          />
        </el-form-item>
        <el-form-item label="确认密码：" :label-width="'60px'">
          <el-input
            v-model="putPasswordForm.confirmPassword"
            type="password"
            show-password
          />
        </el-form-item>
      </el-form>
    </div>
    <button class="button confirm" @click="emitpasword">确定</button>
    <button class="button logout" @click="logout">退出登陆</button>
  </div>
</template>

<style lang="scss" scoped>
.person-setting-page {
  width: 100%;
  height: 100%;
  padding: 20px 45px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  h3 {
    font-size: 25px;
    align-self: flex-start;
  }
  .content {
    width: 100%;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    margin-top: 30px;
    .el-form {
      width: 300px;

      .el-form-item {
        margin-bottom: 20px;
      }
    }
  }

  .button.confirm {
    width: 250px;
    height: 40px;
    flex-shrink: 0;
    margin-top: 30px;
    border: none;
    background-color: #0ecc80;
    color: white;
  }
  .button.logout {
    width: 250px;
    height: 40px;
    flex-shrink: 0;
    margin-top: 30px;
    margin-bottom: 130px;
    border: none;
    background-color: white;
    border: 1px solid #0ecc80;
    color: #0ecc80;
  }
}

@media (max-height: 1000px) {
  .person-setting-page {
    .button.confirm {
      margin-top: 200px;
    }
  }
}
</style>
